package com.base.commonlib.base;

import android.os.Bundle;
import android.view.Gravity;
import android.widget.Toast;

import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.http.utils.SnackBarUtil;
import com.base.commonlib.utils.PbDialog;
import com.base.commonlib.utils.PbMsgDialog;

/**
 * Created by weikailiang on 2019/4/10.
 */

public abstract class CBaseMvpActivity<H extends BasePresenter> extends BaseViewActivity<H>{

    protected PbDialog mPbDialog;
    protected PbMsgDialog mPbMsgDialog;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
        start();
    }

    protected abstract void init();
    protected abstract void start();


    @Override
    public void showPb() {
        if(mPbDialog==null)
        {
            mPbDialog=new PbDialog(mContext);
//            mPbDialog.setCancelable(false);
        }
        if (!mPbDialog.isShowing())
        mPbDialog.show();
    }

    @Override
    public void hidePb() {
        if(mPbDialog!=null)
        {
            mPbDialog.dismiss();
        }
    }

    @Override
    public void showError() {
        Toast toast = Toast.makeText(mContext, "出错了", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
//        SnackBarUtil.showMsg(mRootBinding.getRoot(),"出错了");
    }

    @Override
    public void showPb_mes(String mes) {
        if(mPbMsgDialog==null)
        {
            mPbMsgDialog=new PbMsgDialog(mContext,mes);
//            mPbMsgDialog.setCancelable(false);
        }else
        {
            mPbMsgDialog.setMsg(mes);
        }
        mPbMsgDialog.show();
    }

    @Override
    public void hidePb_mes() {
        if(mPbMsgDialog!=null)
        {
            mPbMsgDialog.dismiss();
        }
    }


}
